package com.zwj.user.controller;

import com.zwj.common.R;
import com.zwj.common.ResultCode;
import com.zwj.common.entity.User;
import com.zwj.common.service.UserService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/user")
public class UserController {

    @Resource
    private UserService userService;

    @GetMapping("/ok")
    public String ok(){

        return "ok";
    }

    @PostMapping("/login/password")
    public R<Object> loginByPassword(@RequestBody User user) {


        Object result = userService.loginByPassword(user);

        if(result instanceof String)
            return R.error((String) result);

        return R.success(result);
    }

    @GetMapping("/getVerificationCode/{phoneNumber}")
    public R<String> getVerificationCode(@PathVariable("phoneNumber") String phoneNumber) {

        String verificationCode = userService.getVerificationCode(phoneNumber);

        return R.success(verificationCode);
    }

    @PostMapping("/login/verificationCode")
    public R<Object> loginByVerificationCode(@RequestBody User user) {

        Object result = userService.loginByVerificationCode(user);

        if(result instanceof String)
            return R.error((String) result);

        return R.success(result);
    }

    @GetMapping("/getUserCount")
    public R<Long> getUserCount() {

        return R.success(userService.getUserCount());
    }


    @GetMapping("/getOnlineUserCount")
    public R<Long> getOnlineUserCount() {

        return R.success(userService.getOnlineUserCount());
    }

//    @GetMapping("/get")



}
